﻿using System.Buffers;
using System.Collections.Generic;

using Microsoft.Extensions.DependencyInjection;

using Xc.DataAccess.Protocoals.WaterMeters.Extensions;

namespace Xc.DataAccess.Protocoals.WaterMeters.Models.Responds
{
    /// <summary>
    /// 修改上报周期和超时限制
    /// </summary>
    public class SetMeterUploadIntervalRespond : MeterFrameRxDataSegmentBase
    {
        public SetMeterUploadIntervalRespond(MeterFrameRx dataArea) : base(dataArea)
        {
        }

        public SetMeterUploadIntervalRespond()
        {
        }

        protected override bool SetData(ref SequenceReader<byte> sequenceReader)
        {
            if (!sequenceReader.TryRead(2, out ReadOnlySequence<byte> status))
            {
                return false;
            }
            this.MeterStatus = new MeterStatus(status.ToArray());
            return true;
        }
        /// <summary>
        /// 表具状态
        /// </summary>
        public MeterStatus MeterStatus { get; private set; }

        internal override IEnumerable<FrameCommand> ValidateCmd
        {
            get
            {
                yield return FrameCommand.CMD06RepOK;
                yield return FrameCommand.CMD06RepNG;
            }
        }

        internal override DataSegment ValidateDataSegment => DataSegment.SetMeterUploadInterval;
    }
}
